/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.ad.entity;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.alibaba.druid.util.StringUtils;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;

/**
 * 广告代理商Entity
 * @author Liu,Wenzhao
 * @version 2019-04-15
 */
@Table(name="ad_agent", alias="a", columns={
		@Column(name="id", attrName="id", label="编号", isPK=true),
		@Column(name="account", attrName="account", label="账户名称", queryType=QueryType.LIKE),
		@Column(name="password", attrName="password", label="账户密码", isQuery=false),
		@Column(name="email", attrName="email", label="账户邮箱", queryType=QueryType.LIKE),
		@Column(name="industry_code", attrName="industryCode.industryCode", label="行业分类"),
		@Column(name="company_name", attrName="companyName", label="公司名称", queryType=QueryType.LIKE),
		@Column(name="contact", attrName="contact", label="联系人", queryType=QueryType.LIKE),
		@Column(name="mobile", attrName="mobile", label="联系电话"),
		@Column(name="upper_agent", attrName="upperAgent", label="上级代理商"),
		@Column(name="upper_agents", attrName="upperAgents", label="上级代理商们", queryType=QueryType.LIKE),
		@Column(name="agent_num", attrName="agentNum", label="开发代理商数量", isInsert=false, isQuery=false),
		@Column(name="customer_num", attrName="customerNum", label="开发广告主数量", isInsert=false, isQuery=false),
		@Column(name="profit_rate", attrName="profitRate", label="利润率", isInsert=false, isQuery=false),
		@Column(name="balance", attrName="balance", label="当前余额", isInsert=false, isQuery=false),
		@Column(includeEntity=DataEntity.class),
		@Column(name="company_website", attrName="companyWebsite", label="公司官网", isQuery=false),
		@Column(name="user_code", attrName="userCode", label="关联用户", isUpdate=false),
	}, joinTable= {
		@JoinTable(type=Type.LEFT_JOIN, entity=AdIndustryType.class, alias="b", 
			on="b.industry_code = a.industry_code", attrName="industryCode",
			columns={@Column(includeEntity=AdIndustryType.class)}),
			
	}, orderBy="a.update_date DESC"
)
public class AdAgent extends DataEntity<AdAgent> {
	
	private static final long serialVersionUID = 1L;
	private String account;		// 账户名称
	private String password;		// 账户密码
	private String email;		// 账户邮箱
	private AdIndustryType industryCode;		// 行业分类
	private String companyName;		// 公司名称
	private String contact;		// 联系人
	private String mobile;		// 联系电话
	private String upperAgent;		// 上级代理商
	private String upperAgents;		// 上级代理商
	private Long agentNum;		// 开发代理商数量
	private Long customerNum;		// 开发广告主数量
	private Double profitRate;		// 利润率
	private Long balance;		// 当前余额
	private String companyWebsite;		// 公司官网
	private String userCode;		// 关联用户
	
	private AdAgent pAgent;//上级代理商
	
	public AdAgent() {
		this(null);
	}

	public AdAgent(String id){
		super(id);
	}
	
	@NotBlank(message="账户名称不能为空")
	@Length(min=0, max=200, message="账户名称长度不能超过 200 个字符")
	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}
	
	@NotBlank(message="账户密码不能为空")
	@Length(min=0, max=255, message="账户密码长度不能超过 255 个字符")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	@NotBlank(message="账户邮箱不能为空")
	@Length(min=0, max=255, message="账户邮箱长度不能超过 255 个字符")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@NotNull(message="行业分类不能为空")
//	@NotBlank(message="行业分类不能为空")
//	@Length(min=0, max=100, message="行业分类长度不能超过 100 个字符")
	public AdIndustryType getIndustryCode() {
		return industryCode;
	}

	public void setIndustryCode(AdIndustryType industryCode) {
		this.industryCode = industryCode;
	}
	
	@Length(min=0, max=200, message="公司名称长度不能超过 200 个字符")
	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}
	
	@Length(min=0, max=10, message="联系人长度不能超过 10 个字符")
	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}
	
	@Length(min=0, max=20, message="联系电话长度不能超过 20 个字符")
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	@Length(min=0, max=64, message="上级代理商长度不能超过 64 个字符")
	public String getUpperAgent() {
		return upperAgent;
	}

	public void setUpperAgent(String upperAgent) {
		this.upperAgent = upperAgent;
	}
	
	public String getUpperAgents() {
		return upperAgents;
	}

	public void setUpperAgents(String upperAgents) {
		this.upperAgents = upperAgents;
	}

	public Long getAgentNum() {
		return agentNum;
	}

	public void setAgentNum(Long agentNum) {
		this.agentNum = agentNum;
	}
	
	public Long getCustomerNum() {
		return customerNum;
	}

	public void setCustomerNum(Long customerNum) {
		this.customerNum = customerNum;
	}
	
	public Double getProfitRate() {
		return profitRate;
	}

	public void setProfitRate(Double profitRate) {
		this.profitRate = profitRate;
	}
	
	public Long getBalance() {
		return balance;
	}

	public void setBalance(Long balance) {
		this.balance = balance;
	}
	
	@Length(min=0, max=255, message="公司官网长度不能超过 255 个字符")
	public String getCompanyWebsite() {
		return companyWebsite;
	}

	public void setCompanyWebsite(String companyWebsite) {
		this.companyWebsite = companyWebsite;
	}
	
	@Length(min=0, max=100, message="关联用户长度不能超过 100 个字符")
	public String getUserCode() {
		return userCode;
	}

	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}

	public AdAgent getpAgent() {
		return pAgent;
	}

	public void setpAgent(AdAgent pAgent) {
		this.pAgent = pAgent;
	}
	
	public void loadUpperAgent(AdAgent upper) {
		if(upper == null) {
			return;
		}
		this.setUpperAgent(upper.getId());
		String agents = StringUtils.isEmpty(upper.getUpperAgents()) ? "" : upper.getUpperAgents();
		this.setUpperAgents(agents + upper.getId() + "," );
	}
}